package com.ash.util;

import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Slf4j
public class ConfigUtil {

    public static Config getConfig() {

        try {
            Properties properties = new Properties();
            // 使用ClassLoader加载properties配置文件生成对应的输入流
            InputStream in = ConfigUtil.class.getClassLoader().getResourceAsStream("config.properties");
            // 使用properties对象加载输入流
            properties.load(in);

            Config config = new Config();
            config.setStoreId(properties.getProperty("storeId"));
            config.setApiToken(properties.getProperty("apiToken"));
            config.setTestMode(Boolean.valueOf(properties.getProperty("testMode")));


            System.out.println("加载配置文件信息");
            System.out.println(config);
            System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
            return config;

        } catch (IOException e) {

            log.error("加载配置文件失败", e);

            throw new RuntimeException(e);
        }


    }
}
